--
-- Author: shunguo.chen
-- Date: 2019-05-24 14:25:47
--
-- RuneIconRender 符文iconRender
--

local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.create(node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.RuneIconNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self._ui.Panel_lock:setVisible(false)
	self:setSelected( false )

	self._type = 1

	display.uiAddClick(self._ui.Panel, function()
		if self._data and not self:isSelected() then
			executeFunc( self._onClick, self)
		end
	end)

end

-- type 1 icon显示技能图标
-- type 2 icon显示符文图标
function ClassRef:setType(type)
	self._type = type
end

-- data = Rune
function ClassRef:refresh()
	local hasData = self._data ~= nil
	self._ui.Panel_lock:setVisible(not hasData)

	if self._data then
		local rune = self._data

		self:refreshDot()
		self._ui.icon:setVisible(true)
		local iconPath = self._type == 1 and rune:getSkillIcon() or rune:getIcon()
		self._ui.icon:loadTexture(iconPath)
	else
		self._ui.icon:setVisible(false)
		self._ui.dot:setVisible(false)
		self:setClickEnable(false)
	end
end

-- 设置响应状态
function ClassRef:setClickEnable( b )
	self._ui.Panel:setTouchEnabled( b )
end

-- 设置选中态
function ClassRef:setSelected( b )
	self._ui.selected:setVisible( b )
end

function ClassRef:isSelected()
	return self._ui.selected:isVisible()
end

-- 刷新红点
function ClassRef:refreshDot()
	if self._data then
		self._ui.dot:setVisible(UD:isSpecRunesHasOp(self._data:getSpecId(), self._data:getEquipPlace()))
	else
		self._ui.dot:setVisible(false)
	end
end

function ClassRef:setDotVisible(b)
	self._ui.dot:setVisible(b)
end

function ClassRef:onBtnClick(func)
	self._onClick = func
end

return ClassRef
